package com.simple.elpmobile.onlinecase.utils;

import java.io.File;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageView;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

public class ImageLoadUtil {

	public static void initImageLoad(Context context, String cachePath) {
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
				context)
				.threadPriority(Thread.NORM_PRIORITY - 2)
				.defaultDisplayImageOptions(
						new DisplayImageOptions.Builder()
								// .showImageForEmptyUri(R.drawable.cover)
								// .showImageOnFail(R.drawable.cover)
								.cacheInMemory(true).cacheOnDisk(true)
								.considerExifParams(true)
								// .displayer(new RoundedBitmapDisplayer(180))
								.bitmapConfig(Bitmap.Config.RGB_565)
								// .displayer(new FadeInBitmapDisplayer(100))
								.build())
				.diskCache(new UnlimitedDiscCache(new File(cachePath)))
				.denyCacheImageMultipleSizesInMemory()
				.diskCacheFileNameGenerator(new Md5FileNameGenerator())
				.tasksProcessingOrder(QueueProcessingType.LIFO).build();
		// Initialize ImageLoader with configuration.
		ImageLoader.getInstance().init(config);
	}

	public static DisplayImageOptions getOptions(int imageRes) {
		return new DisplayImageOptions.Builder()
		.showImageForEmptyUri(imageRes)
		.showImageOnFail(imageRes)
		.showImageOnLoading(imageRes)
		.cacheInMemory(true).cacheOnDisk(true).considerExifParams(true)
		.bitmapConfig(Bitmap.Config.RGB_565).build();
	}

	public static void displayImage(String uri, ImageView imageView,
			DisplayImageOptions options) {
		ImageLoader.getInstance().displayImage(uri, imageView, options);
	}

}
